package com.uwo.commons.samples.controller;

import com.uwo.commons.configuration.aop.validate.annotation.ValidateMethod;
import com.uwo.commons.configuration.aop.validate.excepteion.ApiValidateExceptrion;
import com.uwo.commons.redis.configuration.RedisProperties;
import com.uwo.commons.samples.beans.User;
import com.uwo.commons.samples.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class IndexController {

    @Autowired
    private IndexService indexService;

    @Autowired
    private RedisProperties redisProperties;

    @RequestMapping(value = {"", "/"}, method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public Object index(){
        Map<String, String> maps = new HashMap<String, String>();
        maps.put("key", "index");
        return maps;
    }

    @RequestMapping(value = "/home", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public Object home(){
        Map<String, String> maps = new HashMap<String, String>();
        maps.put("host", redisProperties.getHost());
        return maps;
    }


    @ValidateMethod(responseBean = "testResponse")
    @RequestMapping(value = "/validate", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public Object validate(
            @RequestBody User user,
            String content) throws ApiValidateExceptrion{
        indexService.test1(user, null);
        return indexService.test(user, content);
    }




}
